/* GUI CONVERTED from rcinvchk.p (converter v1.76) Fri Jun 14 04:11:27 2002 */
/* rcinvchk.p - Inventory Status Check                                        */
/*Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                         */
/*All rights reserved worldwide.  This is an unpublished work.                */
/* $Revision: 1.8 $                                                           */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 9.2       CREATED    : 12/15/01     BY: Ashwini G.   *M1LD*      */
/* $Revision: 1.8 $    BY: Sandeep Parab         DATE: 06/04/02  ECO: *M1XH*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* INCLUDE FILE SHARED VARIABLES */
{mfdeclre.i}

/* STANDARD MAINTENANCE COMPONENT INCLUDE FILE */
{pxmaint.i}

/* DEFINE THE PERSISTENT HANDLE */
{pxphdef.i socmnrtn}

/* DEFINE INPUT/OUTPUT PARAMETER */
define input  parameter  l_part    like abs_item    no-undo.
define input  parameter  l_site    like abs_site    no-undo.
define input  parameter  l_loc     like abs_loc     no-undo.
define input  parameter  l_lot     like abs_lot     no-undo.
define input  parameter  l_ref     like abs_ref     no-undo.
define input  parameter  l_qty     like abs_qty     no-undo.
define input  parameter  l_abs_id  like abs_id      no-undo.
define output parameter  l_undo    like mfc_logical no-undo.

/* DEFINE SHARED TEMP-TABLE */
define shared temp-table work_ldd                   no-undo
   field work_ldd_id  like abs_id
   index work_ldd_id  work_ldd_id.

/* DEFINE LOCAL VARIABLES/BUFFER */
define        variable   l_status  like ld_status   no-undo.
define        buffer     ldd_det   for  ld_det.

/* RUN PROCEDURE socmnrtn.p PERSISTENTLY AND SET ph_socmnrtn AS */
/* HANDLE TO PERSISTENT PROCEDURE                               */

{pxrun.i
   &PROC    = 'GetInvStatus'
   &PROGRAM = 'socmnrtn.p'
   &HANDLE  = ph_socmnrtn
   &PARAM   = "(input  l_part,
                input  l_site,
                input  l_loc,
                input  l_lot,
                input  l_ref,
                output l_status,
                buffer ldd_det)"}.

if can-find(first is_mstr
            where is_status    = l_status
            and   is_overissue = no)
then do:
   find first ldd_det
   where ldd_det.ld_part = l_part
   and   ldd_det.ld_lot  = l_lot
   and   ldd_det.ld_ref  = l_ref
   and   ldd_det.ld_site = l_site
   and   ldd_det.ld_loc  = l_loc
   exclusive-lock no-error.

   if  available ldd_det
   and ldd_det.ld_qty_oh > 0
   then do:
      if absolute(l_qty) > ldd_det.ld_qty_oh
      then do:
         l_undo = yes.

         /* UNABLE TO ISSUE OR RECEIVE FOR ITEM */
         {pxmsg.i
            &MSGNUM=161
            &ERRORLEVEL=3
            &MSGARG1=l_part}

         delete PROCEDURE ph_socmnrtn no-error.
         return.
      end. /* IF abs(l_qty) .. */
      else do:
         create work_ldd.
         work_ldd_id = l_abs_id.
      end. /* ELSE DO */
   end. /* IF AVAILABLE ldd_det ... */
   else do:

      for first work_ldd
         fields (work_ld_id)
         where work_ldd_id = l_abs_id
         no-lock:
      end. /* FOR FIRST work_ldd */

      if not available work_ldd
      then do:
         l_undo = yes.

         /* UNABLE TO ISSUE OR RECEIVE FOR ITEM */
         {pxmsg.i
            &MSGNUM=161
            &ERRORLEVEL=3
            &MSGARG1=l_part}

         delete PROCEDURE ph_socmnrtn no-error.
         return.
      end. /* IF NOT AVAILABLE work_ldd  */
   end. /* ELSE DO - IF NOT AVAILABLE ldd_det */
   release ldd_det.
end. /* IF CAN-FIND is_mstr... */

delete PROCEDURE ph_socmnrtn no-error.
